package com.sugar.queryinfo.module.business.service.dataquerylsbg;

import com.sugar.queryinfo.module.business.controller.admin.data.dataquerylsbg.vo.DataQueryLsbgPageReqVO;
import com.sugar.queryinfo.module.business.controller.admin.data.dataquerylsbg.vo.DataQueryLsbgSaveReqVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;

import com.sugar.queryinfo.module.business.dal.dataobject.dataquerylsbg.DataQueryLsbgDO;
import com.sugar.queryinfo.framework.common.pojo.PageResult;
import com.sugar.queryinfo.framework.common.util.object.BeanUtils;

import com.sugar.queryinfo.module.business.dal.mysql.dataquerylsbg.DataQueryLsbgMapper;

import static com.sugar.queryinfo.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.sugar.queryinfo.framework.common.util.collection.CollectionUtils.convertList;
import static com.sugar.queryinfo.module.business.enums.ErrorCodeConstants.*;

/**
 * 数据查询-流水报告 Service 实现类
 *
 * @author Ysugar
 */
@Service
@Validated
public class DataQueryLsbgServiceImpl implements DataQueryLsbgService {

    @Resource
    private DataQueryLsbgMapper dataQueryLsbgMapper;

    @Override
    public Long createDataQueryLsbg(DataQueryLsbgSaveReqVO createReqVO) {
        // 插入
        DataQueryLsbgDO dataQueryLsbg = BeanUtils.toBean(createReqVO, DataQueryLsbgDO.class);
        dataQueryLsbgMapper.insert(dataQueryLsbg);

        // 返回
        return dataQueryLsbg.getId();
    }

    @Override
    public void updateDataQueryLsbg(DataQueryLsbgSaveReqVO updateReqVO) {
        // 校验存在
        validateDataQueryLsbgExists(updateReqVO.getId());
        // 更新
        DataQueryLsbgDO updateObj = BeanUtils.toBean(updateReqVO, DataQueryLsbgDO.class);
        dataQueryLsbgMapper.updateById(updateObj);
    }

    @Override
    public void deleteDataQueryLsbg(Long id) {
        // 校验存在
        validateDataQueryLsbgExists(id);
        // 删除
        dataQueryLsbgMapper.deleteById(id);
    }

    @Override
        public void deleteDataQueryLsbgListByIds(List<Long> ids) {
        // 删除
        dataQueryLsbgMapper.deleteByIds(ids);
        }


    private void validateDataQueryLsbgExists(Long id) {
        if (dataQueryLsbgMapper.selectById(id) == null) {
            throw exception(DATA_QUERY_LSBG_NOT_EXISTS);
        }
    }

    @Override
    public DataQueryLsbgDO getDataQueryLsbg(Long id) {
        return dataQueryLsbgMapper.selectById(id);
    }

    @Override
    public PageResult<DataQueryLsbgDO> getDataQueryLsbgPage(DataQueryLsbgPageReqVO pageReqVO) {
        return dataQueryLsbgMapper.selectPage(pageReqVO);
    }

}